from media.lib.views import FileUploadFormMixin
from project.views.lib import (
    HTMXProjectSubCreateFormView,
    HTMXProjectSubUpdateFormView,
    ProjectSubDetailView,
    ProjectSubListView,
    template_path,
)

from .. import forms, models


class MaterialListView(ProjectSubListView):
    template_name = template_path("material/list.html")

    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        project = self.get_project()
        context["project"] = project
        context["count"] = project.material_set.count()
        return context

class MaterialCreateView(
    FileUploadFormMixin,
    HTMXProjectSubCreateFormView
):
    form_class = forms.MaterialForm
    create_view_name = "project:material/create"
    detail_view_name = "project:material/detail"

class MaterialDetailView(ProjectSubDetailView):
    model = models.Material
    form_class = forms.MaterialForm
    template_name = template_path("material/detail.html")

class MaterialUpdateView(
    FileUploadFormMixin,
    HTMXProjectSubUpdateFormView
):
    model = models.Material
    form_class = forms.MaterialForm
    update_view_name = "project:material/update"
    detail_view_name = "project:material/detail"
